<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 0;
            padding: 50px;
        }

        #sizeInfo {
            font-size: 24px;
            margin-top: 20px;
        } */



        /* body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }

        #sidebar {
            width: 250px;
            height: 100vh;
            background-color: #333;
            color: white;
            float: left;
            padding: 20px;
        }

        #content {
            margin-left: 250px;
            padding: 20px;
        } */


        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 0;
            padding: 50px;
        }

        canvas {
            background-color: #f3f3f3;
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <!-- 动态更新窗口尺寸事件 -->
    <!-- <h1>Resize Event Example</h1>
    <p>Try resizing the browser window.</p>
    <div id="sizeInfo"></div>

    <script>
        const sizeInfo = document.querySelector('#sizeInfo')
        function uput() {
            const width = window.innerWidth;
            const height = window.innerHeight;
            sizeInfo.textContent = `window Size: ${width}px x ${height}px`;

        }
        window.addEventListener('resize', uput)
        uput()
 </script> -->

    <!-- // 该示例实时显示浏览器窗口的尺寸，当用户调整窗口大小时，页面上的尺寸信息会自动更新 -->
    <!--  <div id="sidebar">
        Sidebar Content
    </div>
    <div id="content">
        Main Content
    </div>

     <script>
        function adjust() {
            const sidebar = document.querySelector('#sidebar')
            const content = document.querySelector('#content')

            if (window.innerWidth < 600) {
                sidebar.style.width = '100%';
                content.style.marginLeft = '0';
            } else {
                sidebar.style.width = '250px';
                content.style.marginLeft = '250px';
            }
        }
        window.addEventListener('resize', adjust)
        adjust()

    </script> -->

    <!-- 该示例调整页面布局，根据窗口宽度变化调整侧边栏和内容区的布局，适应不同的屏幕大小。 -->
    <h1>Resize to Redraw Chart</h1>
    <canvas id="myChart"></canvas>
    <script>
        const myChart = document.querySelector('#myChart')
        const ctx = myChart.getContext('2d');

        function drawchart() {
            const width = window.innerWidth * 0.8;
            const height = window.innerHeight * 0.5;
            myChart.width = width;
            myChart.height = height;

            // 简单绘制一个矩形示例
            ctx.fillStyle = 'blue';
            ctx.fillRect(0, 0, width, height);
            ctx.fillStyle = 'white';
            ctx.fillText('Chart Redrawn', width / 2 - 50, height / 2);
        }
        window.addEventListener('resize', drawchart)
        drawchart()
    </script>
</body>

</html>